package Thread;

/*守护线程,又称为后台线程
当一个进程中的所有前台线程都结束时,进程就
要结束,若还有后台线程运行,那么后台线程会
被强制结束。*/
public class ThreadDaemon {
    public static void main(String[] args) {
        Thread ros=new Thread(){
          public void run(){
              for (int i = 0; i < 10; i++) {
                  System.out.println("ros:let me go!");
                  try {
                      Thread.sleep(1000);
                  } catch (InterruptedException e) {
                      e.printStackTrace();
                  }
              }
              System.out.println("ros:啊啊啊啊啊啊啊啊啊啊啊啊");
              System.out.println("落水。。");
          }
        };


        Thread jack=new Thread(){
          public void run(){
              while (true){
                  System.out.println("jack: you jump i jump");
                  try {
                      Thread.sleep(1000);
                  } catch (InterruptedException e) {
                      e.printStackTrace();
                  }
              }
          }
        };


        //必须字启动线程前 设置守护线程
        jack.setDaemon(true);
        ros.start();
        jack.start();
//        main是前台线程
//        while (true);
//        System.out.println("mian 结束");
    }
}
